/*
 * @ author madman 
 * @ use 后台基本参数
 */
const SystemModel = require('../../models/system/system.model');
const Utils = require('../utils');
import md5 from 'md5';
class SystemController {
    // 添加
    async add(ctx) {
        const _body = ctx.request.body
        const _params = Utils._params(_body)
        const _Id = await SystemModel.findOne({'_id':'SYS'});
        let  result
        if(_Id){
           result = await SystemModel.update({ _id: "SYS" }, { $set: _params });
        }else{
           result = await SystemModel.create(_params);
        }
        if (result) {
            return ctx.success({ msg: (_Id?'更新':'添加')+'成功' });
        } else {
            return ctx.error({ msg: (_Id?'更新':'添加')+'失败' });
        }
    }
    // 查询
    async query(ctx) {
        var result = await SystemModel.findOne({ _id: "SYS" })
        if (result) {
            return ctx.success({ msg: '查询成功', data: result});
        } else {
            return ctx.error({ msg: '查询失败' });
        }
    }
}

export default new SystemController;